package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.MaintainRoom;
import com.xuetang9.t9.hotel.mapper.condition.ICondition;
import com.xuetang9.t9.hotel.mapper.sql.impl.MaintainRoomMapperSql;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Pang
 */
@Repository
public interface IMaintainRoomMapper {

    /**
     * 新增维修房间记录
     * @param maintainRoom
     * @return
     */
    @Insert("INSERT INTO g_maintainroom(maintain_type,room_id,staff_id,end_date,naintain_reason,maintain_result,maintain_comment) " +
            "VALUES(#{maintainType},#{roomId},#{staffId},#{endDate},#{naintainReason}," +
            "#{maintainResult},#{maintainComment})")
    int insert(MaintainRoom maintainRoom);

    /**
     * 修改维修房间记录
     * @param maintainRoom
     * @return
     */
    @Update("UPDATE g_maintainroom SET room_id=#{roomId},staff_id=#{staffId},end_date=#{endDate},naintain_reason=#{naintainReason}," +
            "maintain_state=#{maintainState},maintain_result=#{maintainResult},maintain_comment=#{maintainComment} WHERE  maintain_id=#{maintainId}")
    int update(MaintainRoom maintainRoom);

    /**
     * 删除维修房间记录
     * @param id
     * @return
     */
    @Delete("DELETE FROM g_maintainroom WHERE maintain_id=#{maintainId}")
    int delete(Integer id);

    /**
     * 分页限制条件查询
     * @param maintainRoomCondition
     * @return
     */
    @SelectProvider(value = MaintainRoomMapperSql.class,method = "selectByAll")
    @Results(value = {
            @Result(column = "room_id",property = "roomInfo",one = @One(select = "com.xuetang9.t9.hotel.mapper.IRoomInfoMapper.selectByRoomId",fetchType = FetchType.EAGER)),
            @Result(column = "staff_id",property = "staffInfo",one = @One(select = "com.xuetang9.t9.hotel.mapper.IStaffInfoMapper.selectById",fetchType = FetchType.EAGER))
    })
    List<MaintainRoom> selectByAll(@Param("key") ICondition maintainRoomCondition);

    /**
     * 查询总数量
     * @param maintainRoomCondition
     * @return
     */
    @SelectProvider(value = MaintainRoomMapperSql.class,method = "selectByCount")
    Long selectByCount(@Param("key") ICondition maintainRoomCondition);


}
